from django.db import models


class Course(models.Model):
    """
        课程表
    """
    LEVEL_CHOICES = (
        (0, "初级"),
        (1, "中级"),
        (2, "高级")
    )

    name = models.CharField(max_length=128, verbose_name='课程名')
    pic = models.ImageField(verbose_name='课程图片')  # todo 文件保存位置
    sketch = models.CharField(max_length=1024, verbose_name='课程简述')
    level = models.IntegerField(choices=LEVEL_CHOICES, default=0, verbose_name="课程难度")
    duration = models.IntegerField(default=0, verbose_name="时长/小时")
    chapter = models.IntegerField(default=0, verbose_name='章节数')
    course_type = models.CharField(max_length=128, verbose_name='课程类别', default="")
    learners_number = models.IntegerField(default=0, verbose_name="学习人数")
    course_notice = models.CharField(max_length=128, verbose_name="课程公告", default="")
    collection_number = models.IntegerField(default=0, verbose_name='收藏数')

    # organization = models.ForeignKey(verbose_name='机构') # todo

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'course'
        verbose_name = '课程'
        verbose_name_plural = verbose_name


class DataDownload(models.Model):
    """
    资料下载
    """
    name = models.CharField(max_length=64, verbose_name='资料名')
    url = models.URLField(verbose_name="下载url")
    course = models.ForeignKey(to=Course, related_name='course', verbose_name='所属课程', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "资料下载"
        verbose_name_plural = verbose_name
